package netframe;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/12/15.
 */
public class GetRetrofit {
    private volatile static NetInterface retrofit = null;
    private volatile static NetInterface retrofit2 = null;
    private volatile static NetInterface retrofit3 = null;

    public static NetInterface getRetrofit() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(NetAddress.PATH)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(GetClient.getClient())
                .build();
        return retrofit.create(NetInterface.class);
    }
    public static NetInterface getRetrofit2() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(NetAddress.PATH2)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(GetClient.getClient())
                .build();
        return retrofit.create(NetInterface.class);
    }

    public static NetInterface getRetrofit3() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(NetAddress.PATH3)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(GetClient.getClient())
                .build();
        return retrofit.create(NetInterface.class);
    }

    public static NetInterface getInstance() {
        if (retrofit == null) {
            synchronized (NetInterface.class) {
                if (retrofit == null) {
                    retrofit = getRetrofit();
                }
            }
        }
        return retrofit;
    }

    public static NetInterface getInstance2() {
        if (retrofit2 == null) {
            synchronized (NetInterface.class) {
                if (retrofit2 == null) {
                    retrofit2 = getRetrofit2();
                }
            }
        }
        return retrofit2;
    }

    public static NetInterface getInstance3() {
        if (retrofit3 == null) {
            synchronized (NetInterface.class) {
                if (retrofit3 == null) {
                    retrofit3 = getRetrofit3();
                }
            }
        }
        return retrofit3;
    }
}
